/*项目二
场景2物流系统
2018-4-17

tips:新建数据文件
使用for循环定义数据
*/

addModule({
    name:"Logistics System",

    init:function(){
        addSceneFunc("Logistics-system", this.scene, this.name, null);
    },

    config: {
        duration : 5000,
        part1_circle_r : 30,
        rose_r_R : [50,200],
        startAngle : 0,
        position : ["50%","50%"]
    },

    graphic: {
        opt: {},
        circle: [],
    },

    scene:function(){  
        var circle = new Array(); 
        var r = this.config.part1_circle_r;
        
        //非默认参数时重新设置参数
        var len = this.config.label_name.length;
        var len2;
        if (this.config.label_color == null) {
			len2 = 0;
        } else {
        	len2 = this.config.label_color.length;
        }
        var pie_value = new Array(len);    
        var color = new Array(len);
        var data = new Array(len*2);

        //完成配额重新配置
        for(var i = 0; i<len; i++){
            if(i%2==0){
                pie_value[i] = 19;
            }else{
                pie_value[i] = 21;
            }
        }
        pie_value[len-1] = 20;
        this.config.pie_value = pie_value;

        //获取渐变配色
        if(len != len2){
            var h = 0;
            var s = 50;
            var l = 50;
            
            for(var c =0; c < len; c++){
                var n = 360/len;
                var value = 'hsl(' + h + ',' + s + '%,' + l + '%)';
           
                color[c] = value;
                h = h + n;
            }
            this.config.label_color = color;
        }

        //空白部分设置
        for (var i = 0; i < (len-1); i++){
            var down = {
                "value": this.config.pie_value[len-1],
                "name": "8",
                "itemStyle": {
                    "normal": {
                        "color": "#fff"
                        }
                    }
            }
            data[i] = down;
        }

        //文字的部分
        for (var j = len; j < (data.length-1); j++){
            var up = {
                "value": this.config.pie_value[j-len],
                "name": this.config.label_name[j-len+1],
                "label": {
                    "normal": {
                        "position": 'inner'
                    }
                },
                "itemStyle": {
                    "normal": {
                        "color": this.config.label_color[j-len+1]
                    }
                } 
            }
            data[j] = up;
        }

        //动画设置
        zr.configLayer(0, {
            motionBlur: false
        });

        this.graphic.circle = circle;
        var circle0 = new echarts.graphic.Circle({
            shape: {
                cx: _width/2,
                cy: _height/2,
                r: r
            },
            style: {
                fill: this.config.label_color[0],
                text: this.config.label_name[0],
                textFill: "#fff"
            },
            silent: true,
            zlevel: 0,
        });

        circle.push(circle0);
        circle0.animate('', false)
        .when(2000)
        .start('cubicIn');
      
        zr.add(circle0);

        option = {
            backgroundColor: '#fff',
            "series": [{
                "type": "pie",
                // "zlevel": 0,
                "radius": this.config.rose_r_R,
                "avoidLabelOverlap": false,
                "startAngle": this.config.startAngle,
                "center": this.config.position,
                "roseType": "radius",
                "selectedMode": "single",
                "data": data
            }]
        };
                
        this.graphic.opt=option;
        myChart.setOption(option);

        addRenderFunc("logistics-system-stage1", function(){
            endScene();
            zr.remove(circle0);
            myChart.clear();
        }, {
            once : true,
            delay : this.config.duration
        });
    }

});
